package mr

//
// RPC definitions.
//
// remember to capitalize all names.
//

import (
	"fmt"
	"os"
	"strconv"
)

const (
	REDUCE_TASK    = 5
	MAP_TASK       = 1
	STOP_WORK_TASK = 2
	WAIT_NEXT_TASK = 3
	INIT_TASK      = 4
)

type RpcTask struct {
	TaskType   int
	SourceFile string
	NReduce    int
}

func (t RpcTask) String() string {
	taskTypeStr := ""
	switch t.TaskType {
	case REDUCE_TASK:
		taskTypeStr = "REDUCE_TASK"
	case MAP_TASK:
		taskTypeStr = "MAP_TASK"
	case STOP_WORK_TASK:
		taskTypeStr = "STOP_WORK_TASK"
	case WAIT_NEXT_TASK:
		taskTypeStr = "WAIT_NEXT_TASK"
	case INIT_TASK:
		taskTypeStr = "INIT_TASK"
	}
	return fmt.Sprintf("{%v, %v, %v}", taskTypeStr, t.SourceFile, t.NReduce)
}

//
// example to show how to declare the arguments
// and reply for an RPC.
//

type ExampleArgs struct {
	X int
}

type ExampleReply struct {
	Y int
}

// Add your RPC definitions here.

// Cook up a unique-ish UNIX-domain socket name
// in /var/tmp, for the coordinator.
// Can't use the current directory since
// Athena AFS doesn't support UNIX-domain sockets.
func coordinatorSock() string {
	s := "/var/tmp/824-mr-"
	s += strconv.Itoa(os.Getuid())
	return s
}
